import { defineStore } from "pinia";

import { getTopCategory } from '@/api/category'

export const useCategoryStore = defineStore({
  id: "category",
  state: () => ({
    topNavList: [],
  }),
  getters: {},
  actions: {
    async getTopNavList(){
        try{
            const res = await getTopCategory()
            res.result.forEach(ele => {
              ele.open = false
            });
            this.topNavList = res.result
        }catch(err){
            console.log('getTopNavList', err)
        }
    },
    show(curr){
      const selected = this.topNavList.find(item => item.id === curr.id)
      selected.open = true
    },
    hide(curr){
      const selected = this.topNavList.find(item => item.id === curr.id)
      selected.open = false
    }
  },
});
